﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace BDSim
{
    /// <summary>
    /// 读取极移和跳秒文件动态库封装
    /// </summary>
    class ReadEOP
    {
        /// <summary>
        /// 读EOP文件初始化，读取start到end之间的极移和跳秒数据
        /// </summary>
        /// <param name="filename">EOP全路劲文件名</param>
        /// <param name="start">起始时间</param>
        /// <param name="end">结束时间</param>
        /// <returns>执行成功返回true，否则返回false</returns>
        [DllImport("ReadEOP.dll", EntryPoint = "EOP_Init", CallingConvention = CallingConvention.Cdecl)]
        public static extern bool EOP_Init(char[] filename, UTCTime start, UTCTime end);

        /// <summary>
        /// 获取极移和跳秒数据
        /// </summary>
        /// <param name="count">数据个数</param>
        /// <returns>极移和跳秒数据的首地址</returns>
        [DllImport("ReadEOP.dll", EntryPoint = "EOP_GetEopData", CallingConvention = CallingConvention.Cdecl)]
        unsafe public static extern EOPData* EOP_GetEopData(out int count);

        /// <summary>
        /// 获取EOP文件信息
        /// </summary>
        /// <param name="filename">EOP全路劲文件名</param>
        /// <param name="info">文件信息</param>
        /// <returns>1:成功; 负数和0:失败</returns>
        [DllImport("ReadEOP.dll", EntryPoint = "EOP_GetEopInfo", CallingConvention = CallingConvention.Cdecl)]
        public static extern int EOP_GetEopInfo(char[] filename, out EopFileInfo info);

        /// <summary>
        /// 获取跳秒值
        /// </summary>
        /// <param name="time">UTC时间</param>
        /// <returns>GPST-UTC的差值，如果是-9999表示调用失败</returns>
        [DllImport("ReadEOP.dll", EntryPoint = "EOP_GetLeapSec", CallingConvention = CallingConvention.Cdecl)]
        public static extern int EOP_GetLeapSec(UTCTime time);

        /// <summary>
        /// 获取极移值
        /// </summary>
        /// <param name="time">UTC时间</param>
        /// <returns>极移值</returns>
        [DllImport("ReadEOP.dll", EntryPoint = "EOP_GetUtPole", CallingConvention = CallingConvention.Cdecl)]
        public static extern PoleMotion EOP_GetUtPole(UTCTime time);
    }
}
